// pages/Apply_list/Apply_list.js
var call = require("../../utils/ajax.js")

var host = 'http://localhost:8085/';
Page({

    /**
     * 页面的初始数据
     */
    data: {
        appleList: [],
        petsess: "",
        imgPath: "",
        petmess: "",
        countNum: 0
    },

    /**
     * 生命周期函数--监听页面加载
     */



    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onLoad: function(options) {
        console.log(options)
        let imgPath = options.imgPath
        this.setData({
            countNum: options.countNum
        })
        var that = this;
        console.log(options.countNum)
        var url = "Pet/SelectAdoptInforms?pet_id=" + options.pet_id
        call.request1(url, {}, function(res) {
                console.log(res);
                that.setData({
                    appleList: res.date
                })
            })
            // var jj = wx.getStorageSync('openID')
            // var url = "Adopt/SelectAdopt?apple_id=" + jj
        var url1 = "Pet/selectOnePet?pet_id=" + options.pet_id
            // call.getData1(url, function(res) {
            //     console.log(res)
            //     that.setData({
            //         appleList: res.date
            //     })
            //     console.log(that.data.appleList)
            // })

        call.getData1(url1, function(res) {
            console.log(res)
            that.setData({
                petmess: res.data.inform
            })
            console.log(that.data.petmess)

        })
    },






    pass: function(e) {
        console.log(e)
        wx.showModal({
            title: '提示',
            content: '确认是否通过申请',
            success: function(res) {
                if (res.confirm) {
                    var apple_id = e.currentTarget.id;
                    var url2 = "Adopt/passAdoptPet?adopt_id=" + apple_id
                    call.request1(url2, {}, function(res) {
                        console.log(res)
                        wx.showToast({
                            title: '操作成功',
                            icon: 'success', //如果要纯文本，不要icon，将值设为'none'
                            duration: 200
                        })
                        setTimeout(() => {
                            wx.navigateBack({
                                delta: 1, // 回退前 delta(默认为1) 页面
                            })
                        }, 200)
                    })
                } else if (res.cancel) {
                    console.log('用户点击取消')
                }
            }
        })
        this.onLoad()

    },
    unpass: function(e) {
        wx.showModal({
            title: '提示',
            content: '确认是否不通过申请',
            success: function(res) {
                if (res.confirm) {
                    var apple_id = e.currentTarget.id;
                    var url3 = "Adopt/updateAdoptStateWei?adopt_id=" + apple_id
                    call.getData1(url3, function(res) {
                        console.log(res)
                        wx.showToast({
                            title: '操作成功',
                            icon: 'success', //如果要纯文本，不要icon，将值设为'none'
                            duration: 200
                        })
                        setTimeout(() => {
                            wx.navigateBack({
                                delta: 3, // 回退前 delta(默认为1) 页面
                            })
                        }, 200)
                    })
                } else if (res.cancel) {
                    console.log('用户点击取消')
                }
            }
        })
        console.log(e)
        this.onLoad()

    },

    // unpass:function() {
    //     wx.request({
    //             //项目的真正接口，通过字符串拼接方式实现
    //             url: host + "Adopt/passAdoptPet?adopt_id=" + pet_id,
    //             header: {
    //                 "content-type": "application/json;charset=UTF-8",
    //                 "x-auth-token": token,
    //             },
    //             success: function(res) {
    //                 console.log(res)
    //                 this.onLoad();
    //             }
    //         }),


    // },
    onReady: function() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function() {

    },
})